package com.myself.basic.gateway.security.config;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;

@Slf4j
@Configuration
@EnableWebFluxSecurity
@RequiredArgsConstructor
@RefreshScope
public class WebfluxSecurityConfig {

    private final IgnoreUriListConfig ignoreUriListConfig;


    @Bean
    public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
        String[] ignoreUris = ignoreUriListConfig.getIgnoreUris().toArray(new String[ignoreUriListConfig.getIgnoreUris().size()]);
        http.csrf().disable()
                .authorizeExchange().pathMatchers(ignoreUris).permitAll()//无需权限校验
        ;
        return http.build();

    }


}